interface TagView {
  path: string
  title: string
  name?: string
}

interface TagsViewState {
  visitedViews: TagView[]
  cachedViews: string[]
}

const state: TagsViewState = {
  visitedViews: [],
  cachedViews: []
}

const mutations = {
  ADD_CACHED_VIEW: (state: TagsViewState, view: TagView) => {
    if (state.cachedViews.includes(view.name as string)) return
    if (view.name) {
      state.cachedViews.push(view.name)
    }
  },
  DEL_CACHED_VIEW: (state: TagsViewState, view: TagView) => {
    const index = state.cachedViews.indexOf(view.name as string)
    index > -1 && state.cachedViews.splice(index, 1)
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
